package com.kaizige.realtor.Controller;

import com.kaizige.realtor.Dao.houseMsgDao;
import com.kaizige.realtor.Dao.houseOwnerDao;
import com.kaizige.realtor.Dao.payDao;
import com.kaizige.realtor.Pojo.houseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class addController {
	@Autowired
	houseMsgDao hmd;
	@Autowired
	payDao pd;
	@GetMapping("/ownAdd")
	public String toOwnAdd(){

		return "/crud/ownAdd";
	}
	@PostMapping("/ownAdd")
	public String ownAdd(@RequestParam("address")String address, @RequestParam("house_type")int house_type,
	                     @RequestParam("per_num")int per_num, @RequestParam("rent")float rent, HttpSession session){
		String user = (String)session.getAttribute("LoginUser");
		houseMsg hm = new houseMsg(user,address,house_type,per_num,rent,0);
		hmd.addHou(hm);
		pd.payRent(user);
		return "redirect:/ownIndex";
	}
}
